require.config({
    paths: {
        "common": "common/common"
    }
    // baseUrl: 'js/common'
});

require(['common'], function(common) {
    var baseUrl = common.defaultStr();
    /*----------
     *ajax数据请求
     *部门页面管理————补助页面
     *部门页面管理————补发页面
     *默认打开该页的时候就已经知道了是那个部门
     *并且只显示该部门的信息
     */

    var user_table = new Vue({
        el: '#main-data',
        data: {
            item: '',
            user: '',
            url: {
                'changePwd': baseUrl + '/usr/user/changePwd.do'
            }
        },
        methods: {
            init: function() {
                var _self = this;
                // _self.user = _self.getCookie('userName');
                _self.user = localStorage.name;
                _self.item = {
                    "loginName": _self.user
                };
            },
            getCookie: function(c_name) {
                if (document.cookie.length > 0) {
                    c_start = document.cookie.indexOf(c_name + "=")
                    if (c_start != -1) {
                        c_start = c_start + c_name.length + 1
                        c_end = document.cookie.indexOf(";", c_start)
                        if (c_end == -1) c_end = document.cookie.length
                        return unescape(document.cookie.substring(c_start, c_end))
                    }
                }
                return ""
            },
            editPwd: function() {
                var _self = this;
                var temp = {}
                if (_self.item.firstPwd == _self.item.originPwd) {
                    alert("不得与初始密码相同");
                    return false;
                } else if (!_self.item.firstPwd == _self.item.secondPwd) {
                    alert("请确认密码输入");
                    return false;
                } else {
                    temp = {
                        "loginName": _self.item.loginName,
                        "firstPwd": btoa(md5(_self.item.firstPwd)),
                        "secondPwd": btoa(md5(_self.item.secondPwd))
                    }
                }


                console.log(temp); // _self.item.firstPwd =
                //     _self.item.secondPwd =
                $.ajax({
                    type: "POST",
                    url: _self.url.changePwd,
                    data: JSON.stringify(temp),
                    contentType: "application/json; charset=utf-8",
                    dataType: 'json',
                    success: function(result) {
                        if (result.status == 1) {
                            alert(result.message);
                            window.location.reload('./subform-editpwd');
                        } else {
                            alert(result.message);
                        }

                    }
                });
            }
        }
    });
    user_table.init();
});